﻿@page "/todo"

<h3>待办事项 (@todos.Count(todo => !todo.IsDone))</h3>
<hr/>
<AntList Bordered="true" DataSource="@todos">
    <ChildContent Context="todo">
    <ListItem class="row">
            <input class="form-check-input col-auto" type="checkbox" @bind="todo.IsDone">
            <input class="form-control flex-grow-1 col" type="text" @bind="todo.Title">
            
    </ListItem>
    </ChildContent>
</AntList>
<hr/>
<div class="row">
    <div class="col-auto">
        <input class="form-control mt-2" placeholder="待办内容" @bind="newTodo">
        <Button Type="primary" @onclick="AddTodo">添加待办</Button>
    </div>
</div>

@code {
    private List<TodoItem> todos=new ();
    private string newTodo;

    public void AddTodo()
    {
        if (!string.IsNullOrWhiteSpace(newTodo))
        {
            todos.Add(new TodoItem { Title = newTodo });
            newTodo = string.Empty;
        }
    }
}
